<?php
require_once("Xiachufang/entity/Food.php");
class FoodLogic {
	/**
	 * 得到指定菜谱下用户做的最新的食物
	 *
	 * @param unknown_type $num
	 * @param unknown_type $recipeId 未指定则表示所有的菜谱
	 * @return unknown
	 */
	static function getLastFoodIds($num=2,$recipeId=NULL) {
		$table = FoodEntity::getTable();
		$recipeCause = $recipeId ? " where recipe_id=".$recipeId : "";
		$sql = "select food_id from ".$table.$recipeCause." order by food_id desc limit ".$num;
		$db = DBMgr::getSlaver($table);
		return $db->query($sql)->asArray1();
	}
	
	/**
	 * 获取指定用户做过的食物
	 *
	 * @param unknown_type $actorId
	 * @param unknown_type $page
	 * @param unknown_type $pageSize
	 * @return PageResult
	 */
	static function pagedGetActorFoodIds($actorId, $page, $pageSize) {
		$table = FoodEntity::getTable();
		$sql = "select food_id from ".$table." where actor_id=".$actorId." order by food_id desc";
		$db = DBMgr::getSlaver($table);
		return $db->fullPagedQuery($sql,$page, $pageSize);
	}
	
	/**
	 * 获取用户做过的食物
	 *
	 * @param unknown_type $actorId
	 * @param unknown_type $num
	 */
	static function getActorFoodIds($actorId, $num = 10) {
		$table = FoodEntity::getTable();
		$sql = "select food_id from ".$table." where actor_id=".$actorId." order by food_id desc limit ".$num;
		$db = DBMgr::getSlaver($table);
		return $db->query($sql)->asArray1();		
	}
}
?>